ARG PYTHON_VERSION=3.11.10
FROM docker.m.daocloud.io/python:${PYTHON_VERSION}-slim

ENV TZ="Asia/Shanghai"
ARG OPENAI_API_KEY
ARG OPENAI_MODEL_NAME
ARG OPENAI_BASE_URL

# 设置工作目录
WORKDIR /app

# 复制应用代码和依赖文件
COPY main.py .
COPY requirements.txt .
COPY SourceHanSerifSC-VF.ttf .


# 更换apt源为国内源
RUN sed -i s:/deb.debian.org:/mirrors.ustc.edu.cn/:g /etc/apt/sources.list.d/debian.sources && \
    sed -i s:/security.debian.org:/mirrors.ustc.edu.cn/:g /etc/apt/sources.list.d/debian.sources && \
    apt-get update && apt-get install -y --no-install-recommends libgtk-3-dev fontconfig \
    && rm -rf /var/lib/apt/lists/*

# 设置pip源为国内源
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    python -m pip install --upgrade pip && \
    pip install -r requirements.txt

# 下载并安装Source Han Serif VF字体
RUN mkdir -p /usr/share/fonts/truetype/source-han-serif-vf && \
    # 请替换以下URL为实际下载链接
    mv SourceHanSerifSC-VF.ttf /usr/share/fonts/truetype/source-han-serif-vf && \
    fc-cache -fv

# 暴露端口
EXPOSE 8501

# 运行命令
CMD ["streamlit", "run", "main.py"]